import { get } from '@/utils'
interface TableValueEnum {
  key: string | { text: string; status?: string }
}
/**通用处理远程table远程搜索 */
export default (api, fieldName?: { label: string; value: string }) => {
  const valueEnum = reactive({} as TableValueEnum)
  const getInfo = () => {
    get({ url: api }).then(({ data }) => {
      data.forEach(element => {
        valueEnum[element[fieldName?.label || 'id']] = { text: element[fieldName?.value || 'name'] }
      })
    })
  }
  getInfo()
  return { valueEnum }
}
